﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--    <link href="/static/css/dialog.css" rel="stylesheet"/>-->
    <!--    <script src="/static/js/dialog.js"></script>-->
    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/layui.js"></script>


    {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>
<style>
    .active{background-color: red!important;border:1px solid red!important;}
</style>
<div class="newtest">
    <div class="container new_serach">
        {volist name="powerList" id="vo"}
        <a class="btn btn-primary btn-sm" href="{$vo['url']}">{$vo.name}</a>
        {/volist}
    </div>

    <div class=" new_serach">
        <form class="layui-form layui-col-md12 x-so" name="searchForm">
        <span> 单位名称：</span>
        <div class="layui-inline layui-form">
            <input class="layui-input" name="keyword"   autocomplete="off">
        </div>

        <span> 类别：</span>
        <div class="layui-inline layui-form">
        <select name="list_type" lay-verify="status"  lay-filter="status" lay-search="" class="select">
        <option value="0">全部</option>
        <option value="1">项目类别</option>
        <option value="2">产业链</option>
        <option value="3">企业类型</option>
        <option value="4">一级分类</option>
        <option value="5">项目流程</option>
        <option value="6">问题类型</option>
        <option value="20">政府投资</option>
        <option value="21">产业类</option>
        </select>
        </div>

        <button class="layui-btn layui-btn-sm serach_btn" data-type="reload" type="button">搜索</button>
        </form>
    </div>

    <div class="new_main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn-sm layui-btn" lay-event="add">添加类别</button>
                {if condition="$pid gt 0"}
                <!--href="{:URL('project/dictionaries/typelist')}"-->
                <a class="layui-btn-sm layui-btn" href="javascript:history.back(-1)">返回大类</a>
                {/if}
            </div>
        </script>


        <table class="layui-hide" id="demo" lay-filter="demo"></table>

        <script type="text/html" id="switchTpl">
            <!--启用禁用操作-->
            <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
        </script>

        <script type="text/html" id="barDemo">
            {{# if(d.type==4 || d.type==5 || d.type==20 || d.type==21){ }}
            <a class="layui-btn layui-btn-sm" href="{URL('project/dictionaries/typelist')}?pid={{d.id}}" >查看子分类</a>
            {{# } }}
            <button class="layui-btn layui-btn-sm"  lay-event="edit">修改</button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
        </script>

    </div>
</div>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<!--弹框js-->
<script src="/static/js/yii.js"></script>
<script>
    var modal=new yii.modal();
    var pid = {$pid};
    layui.use(['form','jquery','layer','laydate','table'], function() { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });
        var url = "{:URL('project/Dictionaries/typelist')}";
        //搜索操作
        $('.serach_btn').click(function () {
            var data=$("form[name='searchForm']").serializeArray();
            var dataVal = {pid:pid};
            $.each(data, function(i, item){
                dataVal[item.name] = item.value;
            });
            var where = dataVal;
            // var keyword = $('input[name="keyword"]').val();
            // var where = {keyword:keyword,status:status,id:pid};
            search(table,url,where)
        });

        var where = {type:'list',pid:pid};
        var data=$("form[name='searchForm']").serializeArray();
        $.each(data, function(i, item){
            where[item.name] = item.value;
        });
        //列表
        var title = "权限列表";
        var cols = [[
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80, align:'center'}
            ,{field: 'name', title: '分类名称', align:'center'}
            ,{field: 'status', title: '状态',templet: '#switchTpl', unresize: true, align:'center'}
            ,{field: 'sort', title: '排序',  align:'center',edit: 'number',width:60}
            // ,{field: 'addtime', title: '创建时间', align:'center',sort: true}
            ,{fixed: 'right',title: '操作', width:300, align:'center', toolbar: '#barDemo'}
        ]];
        showlist(table,url,where,title,cols);


        //监听行工具事件
        table.on('tool(demo)', function(obj) {
            var id = obj.data.id;
            switch (obj.event) {
                case 'edit':
                    modal.initialization({
                        url: "{:URL('project/Dictionaries/typedetail')}",
                        type: "post",
                        data:{
                            id:id
                        }
                    });
                    break;
                case 'del':
                    layer.confirm('是否确定操作?', function(index){
                        let url="{:URL('project/Dictionaries/typedel')}";
                        let where = {id:id,table:"project_type"};
                        publicDel(table,url,where,obj,index,1);
                    });
                    break;
            }
        });

        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    modal.initialization({
                        url: "{:URL('project/Dictionaries/typedetail')}",
                        type: "post",
                    });
                    break;

            };
        });

        //监听单元格编辑
        table.on('edit(demo)', function(obj){
            var value = obj.value; //得到修改后的值
            var id = obj.data.id;
            $.ajax({
                type: "post",
                url: "/common/Common/updateSort",
                data: {id: id,table:'project_type',value:value},
                dataType: "json",
                success: function (data) {
                    if(data.code!=0){
                        layer.alert(data.msg);
                    }
                }
            });
        });

        //监听启用禁用操作
        form.on('switch(sexDemo)', function(obj){
            var id = this.value;
            var state = obj.elem.checked;
            let url = "{:URL('common/together/clickStatus')}";

            if (state == true) {
                let data = {id:id,status:1,table:'project_type',content:1}
                //上线
                publicClickStatus(url,data);
            } else {
                let data = {id:id,status:2,table:'project_type',content:1}
                //下线
                publicClickStatus(url,data);
            }
        });


        //统一modal执行保存action
        modal.on("add",function(data){
            var data=$(modal.getid()).find("form").serialize();
            $.ajax({
                type: "post",
                url: "{:URL('project/Dictionaries/typeadd')}",
                data: data,
                dataType: "json",
                success: function (data) {
                    if(data.code!=0){
                        layer.alert(data.msg);
                    }else{
                        table.reload('demo')
                         $(".modal-header .close").click();
                    }
                }
            });
        });

        //统一modal执行修改action
        modal.on("edit",function(data){
            var data=$(modal.getid()).find("form").serialize();
            $.ajax({
                type: "post",
                url: "{:URL('project/Dictionaries/typesave')}",
                data: data,
                dataType: "json",
                success: function (data) {
                    if(data.code!=0){
                        layer.alert(data.msg);
                    }else{
                        table.reload('demo')
                        //$(".modal-header .close").click();
                    }
                }
            });
        });

    });
</script>
</body>
</html>
